package com.nav.rummy.core;
import java.util.HashSet;

public class Set extends HashSet<Card> implements IArrangement {
	private static final long serialVersionUID = 1L;
	private Card joker;

	public Set(Card joker) {
		this.joker = joker;
	}

	public boolean canAdd(Card card) {
		if (card == null)
			return false;
		if (size() == 0 || joker != null && joker.getRank() == card.getRank())
			return true;
		Card exCard[] = new Card[size()];
		toArray(exCard);
		for (int i = 0; i < exCard.length; i++)
			if (exCard[i].getRank() != joker.getRank()
					&& (exCard[i].getRank() != card.getRank() || exCard[i]
							.getSuit() == card.getSuit()))
				return false;
		return true;
	}
}
